<?

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#
#	FILE:			includes/custom/admin.php
#	FUNCTION:		Custom handler for the Admin page
#	AUTHOR:			Cameron Morrow
#	CREATED:		03/08/2005
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

addContent("<h2 class=\"home\">Admin Home</h2>" .
"<p>Welcome to the <strong>Editor<sup>2</sup></strong> Content Management System.</p>");


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# N E W S L E T T E R S
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# Get pending newsletters that haven't been sent yet
$sql = "SELECT * FROM " . $PROJECT_DB_TABLES["newsletters"] . " WHERE n_autosendgroups != '' AND n_autosenddate <= '" . getFullDate() . "' AND n_autosent = 0";

# Get records
$newsletter_records = getRecord($sql);

# Get newsletter group names
$newsletter_group_details = getAllNewsletterGroupDetails();

# Header
addContent("<h2>Pending Newsletters</h2>");

# If results
if (count($newsletter_records) > 0) {

	addContent("<p>There are " . count($newsletter_records) . " newsletters due to be sent:</p><table class=\"newslettersendlist\" cellspacing=\"0\">");

	foreach ($newsletter_records as $record_count => $record) {

		# Newsletter groups
		$newsletter_group_names = array();
		$newsletter_group_ids = explode(",", $record["n_autosendgroups"]);

		#
		foreach ($newsletter_group_details as $ng_count => $ng) {

			# Position of this ID in the Newsletter Group IDs for this newsletter
			$ng_position = array_search($ng["ng_id"], $newsletter_group_ids);

			# If found
			if ($ng_position !== false) {

				# Add name
				$newsletter_group_names[] = $ng["ng_name"];
			}
		}

		addContent("<tr>" .
			"<th>" . $record["n_name"] . "</th>" .
			"<th class=\"rightalign\"><form name=\"sendnewsletterform" . $record_count . "\" id=\"sendnewsletterform" . $record_count . "\" action=\"adminsendnewsletters.php\" method=\"get\">" .
			"<input type=\"hidden\" name=\"nl\" id=\"nl\" value=\"" . $record["n_id"] . "\" />" .
			"<input type=\"hidden\" name=\"as\" id=\"as\" value=\"1\" />" .
			"<input type=\"submit\" value=\"Send Newsletter\" class=\"savebutton\" />" .
			"</form></th>" .
			"</tr><tr>" .
			"<td>Send to: " . implode(", ", $newsletter_group_names) . "</td>" .
			"<td>Send on: " . formatDate($record["n_autosenddate"]) . "</td>" .
			"</tr>");
	}

	addContent("</table>");

} else {

	addContent("<p>There are no newsletters currently due to be sent.</p>");
}
?>